def can_partition(nums, m):
    sum_total = sum(nums)
    target = sum_total // m
    nums_sorted = sorted(nums, reverse=True)
    groups = [0] * m

    def backtrack(index):
        if index == len(nums_sorted):
            return all(g == target for g in groups)
        current_num = nums_sorted[index]
        for i in range(len(groups)):
            if groups[i] + current_num > target:
                continue
            groups[i] += current_num
            if backtrack(index + 1):
                return True
            groups[i] -= current_num
            if groups[i] == 0:
                break
        return False

    return backtrack(0)

def max_m(nums):
    nums = [6, 4, 3, 3, 2]
    sum_total = sum(nums)
    max_element = max(nums)

    possible_m = []
    for m in range(1, sum_total + 1):
        if sum_total % m != 0:
            continue
        target = sum_total // m
        if target < max_element:
            continue
        possible_m.append(m)

    possible_m.sort(reverse=True)

    max_m = 0
    for m in possible_m:
        if can_partition(nums, m):
            max_m = m
            break
    return max_m


# 测试用例
if __name__ == "__main__":    
    # 测试用例
    test_cases = [
        [6, 4, 3, 3, 2],
        [10, 8, 6, 4, 2],
        [7, 7, 7],
        [5, 4, 3, 2, 1],
        [5, 4, 3, 2],
    ]
    
    for i, test in enumerate(test_cases):
        print(f"测试用例 {i+1} {test}: 最大的m值为 {max_m(test)}")